---
category: String
created: '2020-05-12'
title: 'Convert camelCase to kebab-case and vice versa'
updated: '2021-10-13'
---

**JavaScript version**

```js kebabToCamel.js
const kebabToCamel = (str) => str.replace(/-./g, (m) => m.toUpperCase()[1]);

const camelToKebab = (str) => str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
```

**TypeScript version**

```ts kebabToCamel.ts
const kebabToCamel = (str: string): string => str.replace(/-./g, (m) => m.toUpperCase()[1]);

const camelToKebab = (str: string): string => str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
```

**Examples**

```js examples.js
kebabToCamel('background-color'); // 'backgroundColor'
camelToKebab('backgroundColor'); // 'background-color'
```
